package o;

import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.source.TrackGroupArray;
import java.io.IOException;
import o.aih.c;

public final class ahx implements aih, c {
    private long ʼ;
    public final aih ˊ;
    private c ˋ;
    long ˎ;
    long ˏ;
    private e[] ॱ = new e[0];

    final class e implements aiu {
        private boolean ˊ;
        public final aiu ˋ;
        final /* synthetic */ ahx ˎ;

        public e(ahx o_ahx, aiu o_aiu) {
            this.ˎ = o_ahx;
            this.ˋ = o_aiu;
        }

        public void ˎ() {
            this.ˊ = false;
        }

        public boolean ॱ() {
            return !this.ˎ.ॱॱ() && this.ˋ.ॱ();
        }

        public void ˊ() throws IOException {
            this.ˋ.ˊ();
        }

        public int ˊ(abk o_abk, DecoderInputBuffer decoderInputBuffer, boolean z) {
            int i = 0;
            if (this.ˎ.ॱॱ()) {
                return -3;
            }
            if (this.ˊ) {
                decoderInputBuffer.ˎ(4);
                return -4;
            }
            int ˊ = this.ˋ.ˊ(o_abk, decoderInputBuffer, z);
            if (ˊ == -5) {
                Format format = o_abk.ॱ;
                if (!(format.ʽॱ == 0 && format.ˈ == 0)) {
                    int i2 = this.ˎ.ˎ != 0 ? 0 : format.ʽॱ;
                    if (this.ˎ.ˏ == Long.MIN_VALUE) {
                        i = format.ˈ;
                    }
                    o_abk.ॱ = format.ˋ(i2, i);
                }
                return -5;
            } else if (this.ˎ.ˏ == Long.MIN_VALUE || ((ˊ != -4 || decoderInputBuffer.ˏ < this.ˎ.ˏ) && (ˊ != -3 || this.ˎ.ॱ() != Long.MIN_VALUE))) {
                return ˊ;
            } else {
                decoderInputBuffer.ˊ();
                decoderInputBuffer.ˎ(4);
                this.ˊ = true;
                return -4;
            }
        }

        public int ˊ(long j) {
            if (this.ˎ.ॱॱ()) {
                return -3;
            }
            return this.ˋ.ˊ(j);
        }
    }

    public /* synthetic */ void ˏ(aiw o_aiw) {
        ˋ((aih) o_aiw);
    }

    public ahx(aih o_aih, boolean z, long j, long j2) {
        this.ˊ = o_aih;
        this.ʼ = z ? j : -9223372036854775807L;
        this.ˎ = j;
        this.ˏ = j2;
    }

    public void ˎ(long j, long j2) {
        this.ˎ = j;
        this.ˏ = j2;
    }

    public void ˏ(c cVar, long j) {
        this.ˋ = cVar;
        this.ˊ.ˏ(this, j);
    }

    public void h_() throws IOException {
        this.ˊ.h_();
    }

    public TrackGroupArray ˋ() {
        return this.ˊ.ˋ();
    }

    public long ॱ(akz[] o_akzArr, boolean[] zArr, aiu[] o_aiuArr, boolean[] zArr2, long j) {
        this.ॱ = new e[o_aiuArr.length];
        aiu[] o_aiuArr2 = new aiu[o_aiuArr.length];
        for (int i = 0; i < o_aiuArr.length; i++) {
            this.ॱ[i] = (e) o_aiuArr[i];
            o_aiuArr2[i] = this.ॱ[i] != null ? this.ॱ[i].ˋ : null;
        }
        long ॱ = this.ˊ.ॱ(o_akzArr, zArr, o_aiuArr2, zArr2, j);
        long j2 = (ॱॱ() && j == this.ˎ && ˎ(this.ˎ, o_akzArr)) ? ॱ : -9223372036854775807L;
        this.ʼ = j2;
        boolean z = ॱ == j || (ॱ >= this.ˎ && (this.ˏ == Long.MIN_VALUE || ॱ <= this.ˏ));
        amm.ˏ(z);
        int i2 = 0;
        while (i2 < o_aiuArr.length) {
            if (o_aiuArr2[i2] == null) {
                this.ॱ[i2] = null;
            } else if (o_aiuArr[i2] == null || this.ॱ[i2].ˋ != o_aiuArr2[i2]) {
                this.ॱ[i2] = new e(this, o_aiuArr2[i2]);
            }
            o_aiuArr[i2] = this.ॱ[i2];
            i2++;
        }
        return ॱ;
    }

    public void ˎ(long j, boolean z) {
        this.ˊ.ˎ(j, z);
    }

    public void ॱ(long j) {
        this.ˊ.ॱ(j);
    }

    public long ˎ() {
        boolean z = false;
        if (ॱॱ()) {
            long j = this.ʼ;
            this.ʼ = -9223372036854775807L;
            long ˎ = ˎ();
            if (ˎ != -9223372036854775807L) {
                return ˎ;
            }
            return j;
        }
        long ˎ2 = this.ˊ.ˎ();
        if (ˎ2 == -9223372036854775807L) {
            return -9223372036854775807L;
        }
        boolean z2;
        if (ˎ2 >= this.ˎ) {
            z2 = true;
        } else {
            z2 = false;
        }
        amm.ˏ(z2);
        if (this.ˏ == Long.MIN_VALUE || ˎ2 <= this.ˏ) {
            z = true;
        }
        amm.ˏ(z);
        return ˎ2;
    }

    public long ॱ() {
        long ॱ = this.ˊ.ॱ();
        if (ॱ == Long.MIN_VALUE || (this.ˏ != Long.MIN_VALUE && ॱ >= this.ˏ)) {
            return Long.MIN_VALUE;
        }
        return ॱ;
    }

    public long ˎ(long j) {
        boolean z = false;
        this.ʼ = -9223372036854775807L;
        for (e eVar : this.ॱ) {
            if (eVar != null) {
                eVar.ˎ();
            }
        }
        long ˎ = this.ˊ.ˎ(j);
        if (ˎ == j || (ˎ >= this.ˎ && (this.ˏ == Long.MIN_VALUE || ˎ <= this.ˏ))) {
            z = true;
        }
        amm.ˏ(z);
        return ˎ;
    }

    public long ॱ(long j, abv o_abv) {
        if (j == this.ˎ) {
            return this.ˎ;
        }
        return this.ˊ.ॱ(j, ˎ(j, o_abv));
    }

    public long ˏ() {
        long ˏ = this.ˊ.ˏ();
        if (ˏ == Long.MIN_VALUE || (this.ˏ != Long.MIN_VALUE && ˏ >= this.ˏ)) {
            return Long.MIN_VALUE;
        }
        return ˏ;
    }

    public boolean ˋ(long j) {
        return this.ˊ.ˋ(j);
    }

    public void ˊ(aih o_aih) {
        this.ˋ.ˊ(this);
    }

    public void ˋ(aih o_aih) {
        this.ˋ.ˏ(this);
    }

    boolean ॱॱ() {
        return this.ʼ != -9223372036854775807L;
    }

    private abv ˎ(long j, abv o_abv) {
        long ˎ = anr.ˎ(o_abv.ʻ, 0, j - this.ˎ);
        long ˎ2 = anr.ˎ(o_abv.ᐝ, 0, this.ˏ == Long.MIN_VALUE ? Long.MAX_VALUE : this.ˏ - j);
        return (ˎ == o_abv.ʻ && ˎ2 == o_abv.ᐝ) ? o_abv : new abv(ˎ, ˎ2);
    }

    private static boolean ˎ(long j, akz[] o_akzArr) {
        if (j == 0) {
            return false;
        }
        for (akz o_akz : o_akzArr) {
            if (o_akz != null && !anb.ˏ(o_akz.ʻ().ʽ)) {
                return true;
            }
        }
        return false;
    }
}
